
clear
set matsize 5000
cd <directory>
**********************************************************************************************************************
** Takes the cleaned weather data (from weatherdata_clean.do) and the cleaned productivity data (from productivitydata_clean.do) and merges them together.
**********************************************************************************************************************

use "combinedproductionwithheatclean" , clear
cap drop monthy monthyled
merge m:1 unit using "tamu_allunitsmerge", gen(mm)
keep if mm==3
drop mm


merge m:1 longitude latitude year month day using "weather_2010to2013_allweeklags.dta ", gen(mmm)
keep if mmm==3
drop mmm

g unit1=unit
replace unit=12 if unit==11
merge m:1 unit using "leddetails.dta", gen(m2)
*keep if m2==3
g monthy=year+(month/12)
g monthyled=yearled+(monthled/12)
drop led unitled
g led=monthy>=monthyled
bys unit: egen unitled=mean(led)

replace unit=unit1
drop unit1

foreach var of varlist meant himeant wbgtmeant{
g `var'led=`var'*led
replace `var'led=. if `var'==. | led==.
}

drop dow
g dow=dow(Date)
drop if dow==0
*encode line, gen(rno)
cap drop *meant*led
*drop mm*
foreach var of varlist meant himeant wbgtmeant{
g `var'led=`var'*led
replace `var'led=. if `var'==. | led==.
}
keep if mactualeff!=.
cap drop wbgtmeant2
cap drop wbgtmeant1
save "LEDprojecwithtamudatanew", replace


use "LEDprojecwithtamudatanew", replace
rename wbgtmaxtemperature* wbgtmaxtemp*

rename wbgtmintemperature* wbgtmintemp*

save "LEDprojecwithtamudatanew", replace
